package com.jy.adscm.operation.purchase.controller;



import com.jy.adscm.operation.purchase.bean.Purchasebom;
import com.jy.adscm.operation.purchase.service.PurchasebomService;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;


import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * bom清单表 前端控制器
 * </p>
 *
 * @author lzf
 * @since 2019-05-14
 */
@RestController
@RequestMapping("adscm/operation/purchasebom")
public class PurchasebomController {
@Autowired
    PurchasebomService purchasebomService;
    @RequestMapping("dataImport")
    public SimpleCoreResponse dataImport(){
        return new SimpleCoreResponse("200","修改成功",purchasebomService.dataimport());
    }
    @RequestMapping("disableData")
    public SimpleCoreResponse diableData(){
        return new SimpleCoreResponse("200","修改成功",purchasebomService.disableData());
    }
    @RequestMapping("queryByPid")
    public SimpleCoreResponse queryByPid(Integer pid,String pid2,String pid3,String pid4,String type){
        return new SimpleCoreResponse("200","查询成功",purchasebomService.queryByParentId(pid,pid2,pid3,pid4,type));
    }
    @RequestMapping("queryByFirst")
    public SimpleCoreResponse queryByFirst(){
        return new SimpleCoreResponse("200","查询父级ID成功",purchasebomService.queryByPid());
    }

    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody Purchasebom purchasebom){
        return new SimpleCoreResponse("200","修改成功",purchasebomService.updateById(purchasebom));
    }
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody Purchasebom purchasebom){
        if (AdscmBaseUtils.getInstance().isNotEmpty(purchasebom.getParentId1(),null)){
            if (purchasebom.getParentId1()==0){
                List<Purchasebom> purchaseboms = purchasebomService.queryByParentId(1, null, null, null, purchasebom.getMachineType());
                purchasebom.setParentId1(purchaseboms.size()+1);
            }
        }

        return new SimpleCoreResponse("200","修改成功",purchasebomService.insert(purchasebom));
    }
}

